package SGGStu.reverseStack;

import java.util.Stack;

/**
 * @Author：DijaH
 * @Date：2022/12/28 4:19 下午
 * @Version：1.0.0
 * @Description： 反转一个栈中的数
 */
public class ReverseStack {

    public static void reverse(Stack<Integer> stack){
        if(stack.isEmpty()){
            return;
        }
        Integer f = f(stack);
        reverse(stack);
        stack.push(f);

    }

    public static Integer f(Stack<Integer> stack){
        int result =  stack.pop();
        if(stack.isEmpty()){
            return result;
        }else{
            int last = f(stack);
            stack.push(result);
            return last;
        }

    }

    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        reverse(stack);
    }
}
